package com.twu.biblioteca.library;

import java.util.TreeMap;

public class Books {
    private TreeMap<String, Book> allBooks = new TreeMap<String, Book>();

    public void setAllBooks(TreeMap<String, Book> allBooks) {
        this.allBooks = allBooks;
    }

    public String viewAllBooks() {
        StringBuffer booksString = new StringBuffer();
        for (Book book : allBooks.values()) {
            booksString.append(book.toString() + "\n");
        }
        return booksString.toString();
    }

    public boolean reserveBook(String ISBN) {
        for (Book book : allBooks.values()) {
            if (book.isISBNEqualTo(ISBN)) {
                return true;
            }
        }
        return false;
    }

    public int getTotalNumberOfBooks(){
        return allBooks.size();
    }

    public void addBook(Book book) {
        String bookID = String.valueOf(allBooks.size() + 1);
        allBooks.put(bookID, book);
    }
}
